class Solution(object):
    def isValid(self, s):
        """
        :type s: str
        :rtype: bool
        """
        l = []
        m = {
            ')': '(',
            '}': '{',
            ']': '['
        }
        s_len = len(s)
        for i in range(s_len):
            if not l or s[i] not in m:
                l.append(s[i])
            else:
                if m[s[i]] == l[-1]:
                    l.pop()
                else:
                    return False
        if l:
            return False
        return True
